import axios from 'axios';
import { UserGroupVo } from '@/api/user-group';

export interface RoleVo {
  deleteUserIds: string[];
  deleteUserGroupIds: string[];
  description: string;
  id: string;
  name: string;
  parentId: string;
  parentName: string;
  sysAdminFlag: string;
  sysInnerFlag: string;
  tenantId: string;
  type: string;
  typeName: string;
  userGroupIds: Array<string>;
  userIds: Array<string>;
  organizationIds: string[];
}

export interface resourceVo {
  checkedFlag: any;
  id: string;
  type: string;
  name: string;
  code: string;
  icon: string;
  url: string;
  menuId: string;
}

export interface menusVo {
  checkedFlag: any;
  id: string;
  name: string;
  parentId: string;
  children: menusVo[];
  resources: Array<resourceVo>;
  portalId: string;
}
export interface portalsVo {
  id: string;
  name: string;
  menus: Array<menusVo>;
  checkedFlag: string;
}
export interface userVo {
  id: string;
  loginName: string;
  name: string;
}

export interface RoleListParams {
  name: string;
  page: number;
  rows: number;
}

export interface RoleListRes {
  rows: RoleVo[];
  total: number;
}
export interface RoleFindDTO {
  name?: string;
  type?: string;
}

export interface RoleInfoVo {
  organizationIds: string[];
  portals: Array<portalsVo>;
  menus: Array<menusVo>;
  resources: {
    PICTURE: resourceVo[];
    ICON: resourceVo[];
    BACKENDURL: resourceVo[];
  };
  roleVO: RoleVo;
  users: Array<userVo>;
  userGroups: UserGroupVo[];
}
export interface RoleInfoUpdateDTO {
  menus: Array<menusVo>;
  resources: {
    PICTURE: resourceVo[];
    ICON: resourceVo[];
    BACKENDURL: resourceVo[];
  };
  roleVO: RoleVo;
  portals: portalsVo[];
}
export function selectPageRole(params: RoleListParams) {
  return axios.post<RoleListRes>('tenant/role/findPageRoles', params);
}

export function findRoles(params: RoleFindDTO) {
  return axios.post<RoleVo[]>('tenant/role/findRoles', params);
}

export function roleDetail(id: string) {
  return axios.post<RoleInfoVo>(`tenant/role/detail/${id}`);
}

export function createRole(params: RoleVo) {
  return axios.post<string>('tenant/role/createRole', params);
}

export function editRole(params: RoleInfoUpdateDTO) {
  return axios.post<string>('tenant/role/updateRole', params);
}

export function editRoleBaseInfo(params: RoleVo) {
  return axios.post<string>('tenant/role/updateRoleBaseInfo', params);
}

export function delRole(id: string) {
  return axios.get<string>(`tenant/role/deleteRole/${id}`);
}

export interface RoleTypeVo {
  description: string;
  name: string;
  id: string;
  sortNumber: number;
}

export interface RoleTypeListParams {
  name: string;
  page: number;
  rows: number;
}

export interface RoleTypeListRes {
  rows: RoleTypeVo[];
  total: number;
}

export function selectPageRoleType(params: RoleTypeListParams) {
  return axios.post<RoleTypeListRes>('tenant/role/findPageRoleType', params);
}

export function createRoleType(params: RoleTypeVo) {
  return axios.post<string>('tenant/role/createRoleType', params);
}

export function editRoleType(params: RoleTypeVo) {
  return axios.post<string>('tenant/role/editRoleType', params);
}

export function delRoleType(id: string) {
  return axios.post<string>(`tenant/role/deleteRoleType/${id}`);
}
